import os
import cv2
import sys
import time
import numpy as np
import matplotlib.pyplot as plt

ws_path  = '../build'
file_list = ['yes.jpg']
filepath = os.path.join(ws_path,file_list[0])
jpeg     = plt.imread(filepath)

def stringtodraw(img):
    map_string = "sd@$#^%$&$&*(^*(&%&^$&sdaidih))"

    out_string = ""

    for i in range(img.shape[0]):
        for j in range(img.shape[1]):
            temp = int(img[i,j,0]*0.299 + img[i,j,1]*0.587 + img[i,j,2]*0.114)
            out_string = out_string + map_string[int(temp*len(map_string)/256)]
        out_string += '\n'

    return out_string

jpeg = cv2.resize(jpeg,dsize=(128,96))
print(stringtodraw(jpeg))
tmp_str = stringtodraw(jpeg)
tmp = open('tmp.txt','w')
tmp.write(tmp_str) 
tmp.close()

# print_list = []
# capture = cv2.VideoCapture(os.path.join(ws_path,'water.avi'))
# if(capture.isOpened()):
#     while(1):
#         # tmp = open('tmp.txt','w')
#         flag, img = capture.read()
#         if not flag:
#             break
#         img = cv2.resize(img,(64,48))
#         # tmp.write(stringtodraw(img))
#         print_list.append(stringtodraw(img))

# for i in range(len(print_list)):
#     print(print_list[i])
#     time.sleep(1/1000000)
#     os.system('clear')
